package com.market.controller.wx;

import com.market.bean.MarketFeedback;
import com.market.bean.bo.wx.WxFeedbackSubmitBo;
import com.market.bean.common.BaseRespVo;
import com.market.exception.ValidationException;
import com.market.service.wx.WxFeedbackService;
import com.market.utils.ValidationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:WalterChan
 * @Decription:WxFeedbackController
 * @Date Created in 2023-01-02-9:24
 */



@RestController
@RequestMapping("wx/feedback")
public class WxFeedbackController {
    @Autowired
    WxFeedbackService wxFeedbackService;


    @RequestMapping("submit")
    @PostMapping
    public BaseRespVo submit(@Valid @RequestBody WxFeedbackSubmitBo wxFeedbackSubmitBo , BindingResult bindingResult) throws ValidationException {
//      参数校验
        ValidationUtil.valid(bindingResult);
        BaseRespVo msg = ValidationUtil.getBaseRespVo(bindingResult);
        if (msg!=null) return msg;
//      等待整合subject获取用户id todo
        MarketFeedback marketFeedback = new MarketFeedback();
        marketFeedback.setUserId(12);
        marketFeedback.setUsername("等待整合Subject123");
        //      等待整合subject获取用户id todo
        if (!wxFeedbackSubmitBo.getPicUrls().isEmpty()){

            marketFeedback.setPicUrls(wxFeedbackSubmitBo.getPicUrls().get(0));
        }
        marketFeedback.setContent(wxFeedbackSubmitBo.getContent());
        marketFeedback.setFeedType(wxFeedbackSubmitBo.getFeedType());
        marketFeedback.setHasPicture(wxFeedbackSubmitBo.isHasPicture());
        marketFeedback.setMobile(wxFeedbackSubmitBo.getMobile());




        wxFeedbackService.submit(marketFeedback);

        return BaseRespVo.ok();



    }
}
